{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Solution(object):\n",
    "    def isPerfectSquare(self, num):\n",
    "        \"\"\"\n",
    "        :type num: int\n",
    "        :rtype: bool\n",
    "        \"\"\"\n",
    "        if num == 0:\n",
    "            return False\n",
    "        left = 1\n",
    "        right = num\n",
    "        while left <= right:\n",
    "            mid = (left + right) // 2\n",
    "            cur = mid**2\n",
    "            if cur == num:\n",
    "                return True\n",
    "            elif cur > num:\n",
    "                right = mid - 1\n",
    "            else:\n",
    "                left = mid + 1\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "s = Solution()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 False\n",
      "1 True\n",
      "2 False\n",
      "3 False\n",
      "4 True\n",
      "5 False\n",
      "6 False\n",
      "7 False\n",
      "8 False\n",
      "9 True\n",
      "10 False\n",
      "11 False\n",
      "12 False\n",
      "13 False\n",
      "14 False\n",
      "15 False\n",
      "16 True\n",
      "17 False\n",
      "18 False\n",
      "19 False\n",
      "20 False\n",
      "21 False\n",
      "22 False\n",
      "23 False\n",
      "24 False\n",
      "25 True\n",
      "26 False\n",
      "27 False\n",
      "28 False\n",
      "29 False\n",
      "30 False\n",
      "31 False\n",
      "32 False\n",
      "33 False\n",
      "34 False\n",
      "35 False\n",
      "36 True\n",
      "37 False\n",
      "38 False\n",
      "39 False\n",
      "40 False\n",
      "41 False\n",
      "42 False\n",
      "43 False\n",
      "44 False\n",
      "45 False\n",
      "46 False\n",
      "47 False\n",
      "48 False\n",
      "49 True\n",
      "50 False\n",
      "51 False\n",
      "52 False\n",
      "53 False\n",
      "54 False\n",
      "55 False\n",
      "56 False\n",
      "57 False\n",
      "58 False\n",
      "59 False\n",
      "60 False\n",
      "61 False\n",
      "62 False\n",
      "63 False\n",
      "64 True\n",
      "65 False\n",
      "66 False\n",
      "67 False\n",
      "68 False\n",
      "69 False\n",
      "70 False\n",
      "71 False\n",
      "72 False\n",
      "73 False\n",
      "74 False\n",
      "75 False\n",
      "76 False\n",
      "77 False\n",
      "78 False\n",
      "79 False\n",
      "80 False\n",
      "81 True\n",
      "82 False\n",
      "83 False\n",
      "84 False\n",
      "85 False\n",
      "86 False\n",
      "87 False\n",
      "88 False\n",
      "89 False\n",
      "90 False\n",
      "91 False\n",
      "92 False\n",
      "93 False\n",
      "94 False\n",
      "95 False\n",
      "96 False\n",
      "97 False\n",
      "98 False\n",
      "99 False\n"
     ]
    }
   ],
   "source": [
    "for i in range(100):\n",
    "    print(i, s.isPerfectSquare(i))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
